﻿using Microsoft.AspNetCore.Authorization;
using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.PermissionManagement;

namespace YaAppoint.Permissions
{
    /// <summary>
    /// 用户权限服务
    /// 
    /// 需要用户具备权限管理权限
    /// </summary>
    [Authorize("UserPermissionManagerment")]
    public class UserPermissionService(IPermissionManager permissionManager) : IUserPermissionService, ITransientDependency
    {
        private readonly IPermissionManager _permissionManager = permissionManager;

        /// <summary>
        /// 用户权限授予
        /// </summary>
        public async Task GrantPermissionForUserAsync(Guid userId, string permissionName)
        {
            await _permissionManager.SetForUserAsync(userId, permissionName, true);
        }

        /// <summary>
        /// 解除用户权限授予
        /// </summary>
        public async Task ProhibitPermissionForUserAsync(Guid userId, string permissionName)
        {
            await _permissionManager.SetForUserAsync(userId, permissionName, false);
        }
    }
}
